package com.jie.langlangmall.controller;

import com.jie.langlangmall.common.api.CommonResult;
import com.jie.langlangmall.model.PmsSkuStock;
import com.jie.langlangmall.service.PmsSkuStockService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author Jie
 * @Date 2024/11/24
 * @Email 3217998214@qq.com
 * @Description sku库存管理
 */
@RestController
@Tag(name = "PmsSkuStockController", description = "sku商品库存管理")
@RequestMapping("/sku")
public class PmsSkuStockController {
    @Autowired
    private PmsSkuStockService skuStockService;

    @Operation(summary = "根据商品ID及sku编码模糊搜索sku库存")
    @GetMapping("/{pid}")
    public CommonResult<List<PmsSkuStock>> list(@PathVariable("pid") Long pid,
                                                @RequestParam(value = "keyword", required = false) String keyword) {
        List<PmsSkuStock> skuStockList = skuStockService.list(pid, keyword);
        return CommonResult.success(skuStockList);
    }

    @Operation(summary = "批量更新sku库存信息")
    @PostMapping("/update/{pid}")
    public CommonResult<?> update(@PathVariable Long pid, @RequestBody List<PmsSkuStock> skuStockList) {
        skuStockService.update(pid, skuStockList);
        return CommonResult.success();
    }

}
